// pages/success/success.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    ids:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.load();
  },

  async load(){
    let res=await wx.util.post("msg/get_wx_ids",{type:'user_order'});
    this.setData({
      ids:res.data
    })
  },
  goPage(page) {
    if (page == 1) {
      wx.switchTab({
        url: "/pages/index/index"
      })
    } else {
      wx.switchTab({
        url: "/pages/myOrder/myOrder"
      })
    }
  },
  go(e) {
    let page=e.currentTarget.dataset.page;
    if(this.data.ids.length==0){
      this.goPage(page);
      return;
    }
    let that=this;
    wx.requestSubscribeMessage({
      tmplIds: this.data.ids,
      complete(res){
        that.goPage(page);
      },
      success (res) { },
      fail(res){
        console.log(res)
      }
    })
    
  }
})